home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / FRAMEWIN.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  9KB  |  334 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1992, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.12  $
  6. //
  7. // Definition of class TFrameWindow.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_FRAMEWIN_H)
  10. #define OWL_FRAMEWIN_H
  11.  
  12. #if !defined(OWL_WINDOW_H)
  13. # include <owl/window.h>
  14. #endif
  15. #if !defined(OWL_MENU_H)
  16. # include <owl/menu.h>
  17. #endif
  18.  
  19. #if defined(BI_NAMESPACE)
  20. namespace OWL {
  21. #endif
  22.  
  23. // Generic definitions/compiler options (eg. alignment) preceeding the 
  24. // definition of classes
  25. #include <services/preclass.h>
  26.  
  27. //
  28. // MDI window IDs
  29. //
  30. const int IDW_MDICLIENT     = 32000;  // ID of MDI client window
  31. const int IDW_FIRSTMDICHILD = 32001;  // child window IDs, 32 max to 32032
  32.  
  33. //
  34. // class TMenuItemEnabler
  35. // ~~~~~ ~~~~~~~~~~~~~~~~
  36. // Command enabler for menu items
  37. //
  38. class _OWLCLASS TMenuItemEnabler : public TCommandEnabler {
  39.   public:
  40.     TMenuItemEnabler(HMENU hMenu, uint id, HWND hWndReceiver, int position);
  41.  
  42.     // Override member functions of TCommandEnabler
  43.     //
  44.     void    Enable(bool enable);
  45.     void    SetText(const char far* text);
  46.     void    SetCheck(int check);
  47.  
  48.     // Menu specific member functions
  49.     //
  50.     HMENU   GetMenu();
  51.     int     GetPosition();
  52.  
  53.   protected_data:
  54.     HMENU   HMenu;
  55.     int     Position;
  56. };
  57.  
  58. //
  59. // class TFrameWindow
  60. // ~~~~~ ~~~~~~~~~~~~
  61. // Adds the notion of a client window, keyboard navigation, and special
  62. // processing for commands (see member function EvCommand)
  63. //
  64. class _OWLCLASS TFrameWindow : virtual public TWindow {
  65.   public:
  66.     TFrameWindow(TWindow*        parent,
  67.                  const char far* title = 0,
  68.                  TWindow*        clientWnd = 0,
  69.                  bool            shrinkToClient = false,
  70.                  TModule*        module = 0);
  71.  
  72.     TFrameWindow(HWND hWnd, TModule* module = 0);
  73.    ~TFrameWindow();
  74.  
  75.     // Menubar manipulating functions
  76.     //
  77.     virtual bool    AssignMenu(TResId menuResId);
  78.     virtual bool    SetMenu(HMENU newMenu);
  79.     void            SetMenuDescr(const TMenuDescr& menuDescr);
  80.     const TMenuDescr* GetMenuDescr() const;
  81.     bool            MergeMenu(const TMenuDescr& childMenuDescr);
  82.     bool            RestoreMenu();
  83.     TModule*        GetMergeModule();
  84.  
  85.     HICON           GetIcon() const;
  86.     HICON           GetIconSm() const;
  87.     bool            SetIcon(TModule* iconModule, TResId iconResId);
  88.     bool            SetIconSm(TModule* iconModule, TResId iconResIdSm);
  89.  
  90.     // Client and child window manipulation
  91.     //
  92.     virtual TWindow* GetClientWindow();
  93.     virtual TWindow* SetClientWindow(TWindow* clientWnd);
  94.     void            RemoveChild(TWindow* child);
  95.     virtual HWND    GetCommandTarget();
  96.  
  97.     // Sets flag indicating that the receiver has requested "keyboard
  98.     // handling" (translation of keyboard input into control selections)
  99.     //
  100.     bool            GetKeyboardHandling() const;
  101.     void            SetKeyboardHandling(bool kh=true);
  102.     void            EnableKBHandler();
  103.  
  104.     // Override virtual functions defined by TWindow
  105.     //
  106.     bool            PreProcessMsg(MSG& msg);
  107.     bool            IdleAction(long idleCount);
  108.     bool            HoldFocusHWnd(HWND hWndLose, HWND hWndGain);
  109.     bool            SetDocTitle(const char far* docname, int index);
  110.  
  111.   protected:
  112.     // Constructor & subsequent initializer for use with virtual derivations
  113.     // Immediate derivitives must call Init() before constructions are done.
  114.     //
  115.     TFrameWindow();
  116.     void            Init(TWindow* clientWnd, bool shrinkToClient);
  117.  
  118.     // The event handler functions that are virtual, and not dispatched thru
  119.     // response tables
  120.     //
  121.     // Extra processing for commands: starts with the focus window and gives
  122.     // it and its parent windows an opportunity to handle the command.
  123.     //
  124.     TResult         EvCommand(uint id, HWND hWndCtl, uint notifyCode);
  125.     void            EvCommandEnable(TCommandEnabler& ce);
  126.  
  127.     // Tell child windows frame has minimized/maximized/restored
  128.     //
  129.     void            BroadcastResizeToChildren(uint sizeType, TSize& size);
  130.  
  131.     // Message response functions
  132.     //
  133.     void            EvInitMenuPopup(HMENU hPopupMenu, uint index, bool sysMenu);
  134.     void            EvPaint();
  135.     bool            EvEraseBkgnd(HDC);
  136.     HANDLE          EvQueryDragIcon();
  137.     void            EvSetFocus(HWND hWndLostFocus);
  138.     void            EvSize(uint sizeType, TSize& size);
  139.     void            EvParentNotify(uint event,
  140.                                    uint childHandleOrX,
  141.                                    uint childIDOrY);
  142.  
  143.     void            EvPaletteChanged(THandle hWndPalChg);
  144.     bool            EvQueryNewPalette();
  145.  
  146.     // Override virtual functions defined by TWindow
  147.     //
  148.     void            SetupWindow();
  149.     void            CleanupWindow();
  150.  
  151.     // Accesors to data members
  152.     //
  153.     HWND            GetHWndRestoreFocus();
  154.     void            SetHWndRestoreFocus(HWND hwndRestoreFocus);
  155.     int             GetDocTitleIndex() const;
  156.     void            SetDocTitleIndex(int index);
  157.     void            SetMergeModule(TModule* module);
  158.  
  159.   public_data:
  160.     bool            KeyboardHandling;
  161.  
  162.   protected_data:
  163.     THandle         HWndRestoreFocus;
  164.     TWindow*        ClientWnd;
  165.     int             DocTitleIndex;
  166.     TModule*        MergeModule;
  167.  
  168.   private:
  169.     TMenuDescr*     MenuDescr;
  170.     TModule*        IconModule;
  171.     TResId          IconResId;
  172.     TModule*        IconSmModule;
  173.     TResId          IconSmResId;
  174.     TPoint          MinimizedPos;
  175.     HICON           CurIcon;
  176.     HICON           CurIconSm;
  177.  
  178.     void            Init(TWindow* clientWnd);
  179.     bool            ResizeClientWindow(bool redraw = true);
  180.     TWindow*        FirstChildWithTab();
  181.  
  182.     // Hidden to prevent accidental copying or assignment
  183.     //
  184.     TFrameWindow(const TFrameWindow&);
  185.     TFrameWindow& operator =(const TFrameWindow&);
  186.  
  187.   DECLARE_RESPONSE_TABLE(TFrameWindow);
  188.   DECLARE_STREAMABLE(_OWLCLASS, TFrameWindow, 2);
  189. };
  190.  
  191. // Generic definitions/compiler options (eg. alignment) following the 
  192. // definition of classes
  193. #include <services/posclass.h>
  194.  
  195. #if defined(BI_NAMESPACE)
  196. } // namespace OWL
  197. #endif
  198.  
  199. //----------------------------------------------------------------------------
  200. // Inline implementations
  201. //
  202.  
  203. //
  204. // Construct a menu item enabler.
  205. //
  206. inline TMenuItemEnabler::TMenuItemEnabler(HMENU hMenu, uint id,
  207.                                           HWND hWndReceiver, int position)
  208. :
  209.   TCommandEnabler(id, hWndReceiver),
  210.   HMenu(hMenu),
  211.   Position(position)
  212. {
  213.   if (::GetMenuItemID(HMenu, Position) == uint(-1))
  214.     Flags = NonSender;
  215. }
  216.  
  217. //
  218. // Return the handle of the menu for this menu item.
  219. //
  220. inline HMENU TMenuItemEnabler::GetMenu()
  221. {
  222.   return HMenu;
  223. }
  224.  
  225. //
  226. // Return the position of the menu item.
  227. //
  228. inline int TMenuItemEnabler::GetPosition()
  229. {
  230.   return Position;
  231. }
  232.  
  233. //
  234. // Retrieve handle of icon of frame window
  235. // NOTE: Only retrieves icon set via the 'SetIcon' API - does not retrieve
  236. //       the small HICON associated with the HWND.
  237. //
  238. inline HICON TFrameWindow::GetIcon() const
  239. {
  240.     return CurIcon;
  241. }
  242.  
  243. //
  244. // Retrieve handle of icon of frame window
  245. // NOTE: Only retrieves icon set via the 'SetIconSm' API - does not retrieve
  246. //       the HICON associated with the HWND.
  247. //
  248. inline HICON TFrameWindow::GetIconSm() const
  249. {
  250.   return CurIconSm;
  251. }
  252.  
  253. //
  254. // Return the menu descriptor for the frame window.
  255. //
  256. inline const TMenuDescr* TFrameWindow::GetMenuDescr() const
  257. {
  258.   return MenuDescr;
  259. }
  260.  
  261. //
  262. // Return true if the frame window is handling keyboard messages.
  263. //
  264. inline bool TFrameWindow::GetKeyboardHandling() const
  265. {
  266.   return KeyboardHandling;
  267. }
  268.  
  269. //
  270. // Set the keyboard handling flag for the window.
  271. //
  272. inline void TFrameWindow::SetKeyboardHandling(bool kh)
  273. {
  274.   KeyboardHandling = kh;
  275. }
  276.  
  277. //
  278. // Sets the keyboard handling flag to true.
  279. //
  280. inline void TFrameWindow::EnableKBHandler()
  281. {
  282.   SetKeyboardHandling(true);
  283. }
  284.  
  285. //
  286. // Return the handle of the window to restore focus to.
  287. //
  288. inline HWND TFrameWindow::GetHWndRestoreFocus()
  289. {
  290.   return HWndRestoreFocus;
  291. }
  292.  
  293. //
  294. // Sets the remembered focused window.
  295. //
  296. inline void TFrameWindow::SetHWndRestoreFocus(HWND hwndrestorefocus)
  297. {
  298.   HWndRestoreFocus = hwndrestorefocus;
  299. }
  300.  
  301. //
  302. // Return the document title index.
  303. //
  304. inline int TFrameWindow::GetDocTitleIndex() const
  305. {
  306.   return DocTitleIndex;
  307. }
  308.  
  309. //
  310. // Set the current document's title index.
  311. //
  312. inline void TFrameWindow::SetDocTitleIndex(int index)
  313. {
  314.   DocTitleIndex = index;
  315. }
  316.  
  317. //
  318. // Return the module of the merge menu.
  319. //
  320. inline TModule* TFrameWindow::GetMergeModule()
  321. {
  322.   return MergeModule;
  323. }
  324.  
  325. //
  326. // Remember where the merged menu came from.
  327. //
  328. inline void TFrameWindow::SetMergeModule(TModule* module)
  329. {
  330.   MergeModule = module;
  331. }
  332.  
  333. #endif  // OWL_FRAMEWIN_H
  334.